package org.dandsoft.blackbox.snn;

import java.io.Serializable;

/**
 * Created by IntelliJ IDEA.
 * User: dvilyuzhanin
 * Date: 16.03.2009 18:59:24
 */
public class Value implements Serializable {

    public final static Value PASSIVE = new Value(0);
    public final static Value ACTIVE = new Value(1);

    private float value;

    public Value(float value) {
        this.value = value;
    }

    public float getValue() {
        return value;
    }

    public Value add(Value v) {
        return new Value(this.value + v.getValue());
    }

    public Value weight(Value m) {
        return new Value(this.value * m.getValue());
    }

    public Value part(Value value) {
        return new Value(this.value * 100 / value.getValue());
    }

    public Value countOutValue(Value max, Value bar) {
        //return new Value((this.value - bar.getValue()) * 100 / max.getValue());
        return new Value(this.value / bar.getValue());
    }

    public boolean isGreater(Value v) {
        return this.value > v.getValue();
    }

    public boolean isLower(Value v) {
        return this.value < v.getValue();
    }

    public boolean isEquals(Value v) {
        return this.value == v.getValue();
    }

    public boolean isGreaterEquals(Value v) {
        return isEquals(v) || isGreater(v);
    }

    public boolean isLowerEquals(Value v) {
        return isLower(v) || isEquals(v);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Value value1 = (Value) o;

        if (value != value1.value) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return Float.floatToIntBits(this.value);
    }

    @Override
    public String toString() {
        return "Value{" +
                "value=" + value +
                '}';
    }

    public Value increment() {
        return new Value(value + 1);
    }
}
